import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class Select {
    public static int select(Connection connection) throws SQLException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入查看的sql");
        String sql = sc.nextLine();
        int n = 0;
        PreparedStatement statement = connection.prepareStatement(sql);
        ResultSet resultSet = statement.executeQuery();
        while (resultSet.next()) {
            n++;
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            System.out.println("id: " + id + " name: " + name);
        }
        resultSet.close();
        statement.close();
        return n;
    }
}
